package com.hongxun.modules.csg.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.csg.dao.CGroundDao;
import com.hongxun.modules.csg.entity.CGroundEntity;
import com.hongxun.modules.csg.service.CGroundService;



@Service("cGroundService")
public class CGroundServiceImpl implements CGroundService {
	@Autowired
	private CGroundDao cGroundDao;
	
	@Override
	public CGroundEntity queryObject(String guid){
		return cGroundDao.queryObject(guid);
	}
	
	@Override
	public List<CGroundEntity> queryList(Map<String, Object> map){
		return cGroundDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return cGroundDao.queryTotal(map);
	}
	
	@Override
	public void save(CGroundEntity cGround){
		if(cGround.getGuid()==null||cGround.getGuid().equals("")) {
			cGround.setGuid(UUID.randomUUID().toString());
		}
		cGroundDao.save(cGround);
	}
	
	@Override
	public void update(CGroundEntity cGround){
		cGroundDao.update(cGround);
	}
	
	@Override
	public void delete(String guid){
		cGroundDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		cGroundDao.deleteBatch(guids);
	}

	@Override
	public void insertOrReplaceOrDelete(List<CGroundEntity> entities) {
		for (CGroundEntity d : entities) {
			if (d.getGDatastate().equals("删除")) {
				cGroundDao.delete(d.getGuid());
			} else {
				CGroundEntity cGroundEntity = cGroundDao.queryObject(d.getGuid());
				if (cGroundEntity == null) {
					cGroundDao.save(d);
				} else {
					cGroundDao.update(d);
				}
			}
		}
	}
	
}
